/****************************************************************************
	This file is part of Basqet.

	Basqet is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Basqet is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
    along with Basqet.  If not, see <http://www.gnu.org/licenses/>.

****************************************************************************/

#include "basketmanager.h"

#include "basketcontent.h"

#include "notedata.h"
#include "notepadpagedata.h"
#include "notepadpage.h"

#include <QFileInfo>


/***************************************************************************/
/** Creates a datamanager and opens or creates the basket on the provided
  * location.
  *
  */

BasketManager::BasketManager(const QString& location)
		:mLocation(location),
		mBasketContent(new BasketContent(mLocation)),
		mCommandManager(new CommandManager),
		mTagManager(new TagManager)
{

}

void BasketManager::openBasket()
{
	// Asuming we have all views created by now, we can read the basket content.
	// All views are responsible for listening to the signals indicating a new note.

	mBasketContent->openBasket();

}

NotePadPage* BasketManager::getNotePadPage()
{
	if (!mCurrentNotePadPage)
	{
		mCurrentNotePadPage = new NotePadPage(mBasketContent, mCommandManager, mTagManager);
		connect(mCurrentNotePadPage.data(), SIGNAL(activated(QObject*,UICapabilities)), this, SIGNAL(activated(QObject*,UICapabilities)));
		connect(mCurrentNotePadPage.data(), SIGNAL(deActivated(QObject*,UICapabilities)), this, SIGNAL(deActivated(QObject*,UICapabilities)));
	}
	return mCurrentNotePadPage.data();

}

QExplicitlySharedDataPointer<CommandManager> BasketManager::getCommandManager()
{
	return mCommandManager;

}

QExplicitlySharedDataPointer<TagManager> BasketManager::getTagManager()
{
	return mTagManager;

}

bool BasketManager::verifyBasket()
{
	QFileInfo	basket(mLocation);

	if (basket.exists() && basket.isDir())
		return true;

	return false;

}


void BasketManager::actionSave()
{
	mBasketContent->actionSave();
}

void BasketManager::actionExportTo(QString fileName)
{

	mBasketContent->actionExportBasketTo(fileName);

}

void BasketManager::actionPrintXML()
{
	mBasketContent->printXML();
}
